package com.cl.pile.rule.filter;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author chenyitao
 * @date 2021/1/5
 */
public class ListNoOverlapOperation implements IFilterOperation {
    @Override
    public boolean filterMatch(Object value, String matchValue) {
        if (value == null || matchValue == null) {
            return false;
        }
        if (!String.valueOf(value).contains(",") || !matchValue.contains(",")) {
            return !String.valueOf(value).equals(matchValue);
        }
        Set<String> set1 = new HashSet<>(Arrays.asList(String.valueOf(value).split(",")));
        Set<String> set2 = new HashSet<>(Arrays.asList(matchValue.split(",")));

        // 检查两个集合是否有交集
        set1.retainAll(set2);
        return set1.isEmpty();
    }

    @Override
    public String filterName() {
        return "列表无重合";
    }
}
